#include "rainbowlog.hpp"
#include <cstdio>

void logToConsole(std::string msg, LogLevel level)
{
    const char *color;
    const char *levelStr;
    switch (level)
    {
    case INFO:
        color = COLOR_INFO;
        levelStr = "INFO";
        break;
    case WARNING:
        color = COLOR_WARNING;
        levelStr = "WARNING";
        break;
    case ERROR:
        color = COLOR_ERROR;
        levelStr = "ERROR";
        break;
    case NOTE:
        color = COLOR_NOTE;
        levelStr = "NOTE";
        break;
    }

    printf("%s[%s] %s%s\n", color, levelStr, msg.c_str(), COLOR_RESET);
}

// 日志级别阈值
LogLevel gMinLogLevel = INFO;

/**
 * @brief 初始化日志系统
 *
 * @param minLevel 日志级别阈值
 */
void initRainbowLog(LogLevel minLevel)
{
    gMinLogLevel = minLevel;
}

/**
 * @brief 记录日志消息和级别
 *
 * @param msg 日志消息
 * @param level 日志级别
 */
void logMessage(std::string msg, LogLevel level)
{
    if (level >= gMinLogLevel)
    {
        logToConsole(msg, level);
    }
}